//
//  Hello World server in go
//  Binds REP socket to tcp://*:5555
//  Expects "Hello" from client, replies with "World"
//
package main

import (
	"fmt"
	"zmq"
	"os"
)

func zmq_main() os.Error {
	context, err := zmq.Init(1)
	if err != nil {
		return err
	}
	defer context.Close()
	
	socket, err := context.Socket(zmq.REP)
	if err != nil {
		return err
	}
	defer socket.Close()
	
	err = socket.Bind("tcp://*:5555")
	if err != nil {
		return err
	}
	
	for {
		data, err := socket.Recv(0)
		if err != nil {
			return err
		}
		fmt.Printf("Received %s\n",data)
		//work
		zmq.Sleep(1e9)
		err = socket.Send([]byte("word"),0)
		if err != nil {
			return err
		}
	}	
	return nil
}

func main() {
	fmt.Println("Hello World server!")
	err := zmq_main()
	if err != nil {
		fmt.Println(err)
	}
}
